package com.itheima.controller;

import com.itheima.pojo.SmsFlashPromotion;
import com.itheima.pojo.UmsRole;
import com.itheima.service.SmsFlashPromotionService;
import com.itheima.service.SmsHomeBrandService;
import com.itheima.vo.PageResultVo;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("flash")
public class SmsFlashPromotionController {
    @Autowired
    private SmsFlashPromotionService smsFlashPromotionService;

    /**
     * 添加活动
     * @param
     * @return
     */
    @PostMapping("create")
    public ResponseEntity create(@RequestBody SmsFlashPromotion smsFlashPromotion){
        smsFlashPromotionService.create(smsFlashPromotion);
        return ResponseEntity.ok(Result.success(null));
    }

    /**
     * 删除活动
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public ResponseEntity delete(@PathVariable("id") Integer id){
        smsFlashPromotionService.delete(id);
        return ResponseEntity.ok(Result.success(null));
    }

    /**
     * 分页模糊查询
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("list")
    public ResponseEntity list(@RequestParam(defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize,
                               String keyword){
        PageResultVo<SmsFlashPromotion> resultVo = smsFlashPromotionService.list(pageNum,pageSize,keyword);
        return ResponseEntity.ok(Result.success(resultVo));
    }

    /**
     * 修改上下线状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("update/status/{id}")
    public ResponseEntity status(@PathVariable("id") Integer id,
                               Integer status){
        smsFlashPromotionService.status(id,status);
        return ResponseEntity.ok(Result.success(null));
    }

    /**
     * 编辑活动
     * @param id
     * @param
     * @return
     */
    @PostMapping("update/{id}")
    public ResponseEntity update(@PathVariable("id") Integer id,
                                 @RequestBody SmsFlashPromotion smsFlashPromotion){
        smsFlashPromotionService.update(id,smsFlashPromotion);
        return ResponseEntity.ok(Result.success(null));
    }

    /**
     * 获取活动详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity findById(@PathVariable("id") Integer id){
        SmsFlashPromotion smsFlashPromotion = smsFlashPromotionService.findById(id);
        return ResponseEntity.ok(Result.success(smsFlashPromotion));
    }
}
